package leetcode.code1551;

public class Solution1551 {

	public int minOperations(int n) {
		// 1 ,3 , 5, 7, 9, 11
		int end = this.end(n) - 1;
		int start = (n & 1) == 0 ? 2 : 4;
		return ((start + end) * (n >> 1)) >> 2;// 对称数距离的一半
	}

	public int minOperations1(int n) {
		int sum1 = this.sum(n);// n个数的和
		int sum2 = this.sum(n >> 1);// 一半的和
		return (n & 1) == 0 ? (sum1 >> 1) - sum2 : (sum1 - this.end((n >> 1) + 1) >> 1) - sum2;
	}

	private int sum(int n) {
		return (1 + this.end(n)) * n >> 1;
	}

	private int end(int n) {
		return ((n - 1) << 1) + 1;
	}

	public static void main(String[] args) {
		Solution1551 so = new Solution1551();
		int ans = so.minOperations(5);
		System.out.println(ans);
	}
}
